<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
request.setCharacterEncoding("UTF-8");
String htmlData = request.getParameter("cont") != null ? request.getParameter("cont") : "";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <link rel="stylesheet" href="css/bootstrap.min.css" />
	<link rel="stylesheet" href="kind/themes/default/default.css" />
	<link rel="stylesheet" href="kind/plugins/code/prettify.css" />
  </head>
  
  <body>
    <%@ include file="top.jsp" %>
     <%=htmlData%>
    <div class="container" style="margin-top:60px;">
		<div class="row">
			<div class="span9">
				<form class="form-horizontal" action="goal.jspx?m=edit" method="post" id="myform">
				<fieldset>
					<legend>编辑目标</legend>
					<div class="control-group">
						<label class="control-label" for="input01">目标名称</label>				
						<div class="controls">
							<input type="text" class="span5" id="name" name="name" style="height:28px" value="${goal.name }"/>
							<span id="name-msg" style="color:red"></span><br/>
							<p class="help-block">In addition to  text, any HTML5 text-based input appears like so.</p>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label" >任务描述</label>
						<div class="controls">       
							<textarea class="span7" name="cont" rows="8"><%=htmlspecialchars(htmlData)%>${goal.cont }</textarea>
						</div>
					</div>
					<input type="hidden" name="id" value="${goal.id }"/><br><br>
					<div class="form-actions">
						<button type="button" id="btnSubmit" class="btn btn-primary">保存</button>
                        <a class="btn" href="goal.jspx">返回</a>
					</div>
				</fieldset>
				</form>
			</div>						
		</div>
	</div>
	
	
	<script charset="utf-8" src="kind/kindeditor.js"></script>
	<script charset="utf-8" src="kind/lang/zh_CN.js"></script>
	<script charset="utf-8" src=".kind/plugins/code/prettify.js"></script>
	<script>
		

		function validateName() {
			var name = document.getElementById("name").value;
			if(name.trim().length == 0 ) {
				return false;
			}
			return true;
		}
		document.getElementById("name").onblur = function () {
			var result = validateName();
			if(result) {
				document.getElementById("name-msg").innerHTML = "√";
			}
			if(!result) {
				document.getElementById("name-msg").innerHTML = "×目标名不能为空";
			}
		};
		
		document.getElementById("name").onkeyup = function(){
			document.getElementById("name-msg").innerHTML = "";
		};
		
		document.getElementById("btnSubmit").onclick = function (){	
			//通过button按钮来提及表单
			if(validateName()) {
				document.getElementById("myform").submit();
			} else {
			//若果上述条件不成立则不能提交表单button
				document.getElementById("myform").button();
			}		
		};
		
	</script>
  </body>
</html>
<%!
private String htmlspecialchars(String str) {
	str = str.replaceAll("&", "&amp;");
	str = str.replaceAll("<", "&lt;");
	str = str.replaceAll(">", "&gt;");
	str = str.replaceAll("\"", "&quot;");
	return str;
}
%>